package com.ljx.List;

/**
 * @author 李加喜
 * @Package com.ljx.List
 * @date 2021-11-30 11:11
 */
// 26原地去重  不借用新的数组
public class YuanDi {
    public static void main(String[] args) {
        YuanDi yuanDi = new YuanDi();
        int[] num={1,1,2};
        System.out.println(yuanDi.removeDuplicates(num));
    }
    public int removeDuplicates(int[] nums) {
        int n=nums.length;
        if (n==0){
            return 0;
        }
        int slow=0,fast=0;
        while (fast<n){
            if (nums[slow]!=nums[fast]){
                slow++;
                nums[slow]=nums[fast];
            }
            fast++;
        }
        return ++slow;
    }
}
